package leetcode_1001_1100;

public class LeeCode_1017 {
    public static void main(String[] args) {
        System.out.println(baseNeg2(3));
        System.out.println(baseNeg2(2));
        System.out.println(baseNeg2(4));
        System.out.println(baseNeg2(1));
        System.out.println(baseNeg2(0));
    }
    private static String baseNeg2(int n) {
        if (n == 0)
            return "0";
        StringBuilder sb = new StringBuilder();
        while (n != 1 && n!= 0){
            int yu = n % -2;
            if (yu == -1){
                yu = 1;
                n = n / -2 + 1;
                sb.append(yu);
                continue;
            }
            sb.append(yu);
            n /= -2;
        }
        if (n == 1)
            sb.append(1);
        return sb.reverse().toString();
    }
}
